package com.bcbim.api_web.wisdom_big_screen.controller;

import com.bcbim.api_web.sys.interceptor.TranslateHandle;
import com.bcbim.common.response.annotation.Translate;
import com.bcbim.common.response.annotation.TranslationField;
import com.bcbim.common.response.vo.ReturnMsg;
import com.bcbim.common.sys.Code;
import com.bcbim.common.util.LngLonUtil;
import com.bcbim.smart_water_interface.equipment_alarm_monitoring.service.EquipmentAlarmMonitoringService;
import com.bcbim.smart_water_interface.equipment_alarm_monitoring.vo.listAlarmMessageVO;
import com.bcbim.smart_water_interface.inspection.vo.InspectionPositionVO;
import com.bcbim.smart_water_interface.wisdom_big_screen.service.WisdomBigScreenService;
import com.bcbim.smart_water_interface.wisdom_big_screen.vo.ListAssetInformationVO;
import com.bcbim.smart_water_interface.wisdom_big_screen.vo.ListInspectionInformationVO;
import com.bcbim.smart_water_interface.wisdom_big_screen.vo.ListProblemInformationVO;
import org.apache.dubbo.config.annotation.Reference;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @Description: 智慧大屏 控制层
 * @Author lihonggang
 * @Date 2021/11/03  15:47
 * @Version V1.0
 **/
@RestController
@RequestMapping("/wisdomBigScreen")
public class WisdomBigScreenController {

    @Reference(protocol = "dubbo", group = "wisdomBigScreen", version = "1.0.0")
    private WisdomBigScreenService wisdomBigScreenServiceImpl;

    @Reference(protocol = "dubbo", group = "equipmentAlarmMonitoring", version = "1.0.0")
    private EquipmentAlarmMonitoringService equipmentAlarmMonitoringServiceImpl;

    /**
     * @Description:  等级缺陷统计
     * @Date:  2021/11/3 15:52
     * @Param: []
     * @return: com.bcbim.common.response.vo.ReturnMsg
     * @Author: lihonggang
     **/
    @RequestMapping("/defectRecord")
    public ReturnMsg defectRecord(){
        List<Code> list = wisdomBigScreenServiceImpl.defectRecord();
        return ReturnMsg.consSuccess(list);
    }
    /**
     * @Description:  设备信息统计
     * @Date:  2021/11/3 17:37
     * @Param: [] 
     * @return: com.bcbim.common.response.vo.ReturnMsg
     * @Author: lihonggang
     **/
    @RequestMapping("equipmentRecord")
    public ReturnMsg equipmentRecord(String roadId){
        Map<String, Object> map = new HashMap<>();
        
        int equipmentCount = wisdomBigScreenServiceImpl.equipmentCount(roadId);
        int equipmentOnlineCount = wisdomBigScreenServiceImpl.equipmentOnlineCount(roadId);
        int equipmentOfflineCount = wisdomBigScreenServiceImpl.equipmentOfflineCount(roadId);
        int realtimeAlarmCount = equipmentAlarmMonitoringServiceImpl.pendingCount(roadId);
        
        map.put("equipmentCount",equipmentCount);
        map.put("equipmentOnlineCount",equipmentOnlineCount);
        map.put("equipmentOfflineCount",equipmentOfflineCount);
        map.put("realtimeAlarmCount",realtimeAlarmCount);

        return ReturnMsg.consSuccess(map);
    }
    /**
     * @Description:  查询报警信息列表
     * @Date:  2021/11/4 10:08
     * @Param: [query]
     * @return: com.bcbim.common.response.vo.ReturnPageMsg
     * @Author: lihonggang
     **/
    @RequestMapping("/listAlarmMessage")
    public ReturnMsg listAlarmMessage(){

        List<listAlarmMessageVO> list = wisdomBigScreenServiceImpl.listAlarmMessage();

        return ReturnMsg.consSuccess(list);

    }
    /**
     * @Description:  巡检信息
     * @Date:  2021/11/18 20:15
     * @Param: [query]
     * @return: com.bcbim.common.response.vo.ReturnPageMsg
     * @Author: lihonggang
     **/
    @RequestMapping("/listInspectionInformation")
    public ReturnMsg listInspectionInformation(){

        List<ListInspectionInformationVO> list = wisdomBigScreenServiceImpl.listInspectionInformation();

        return ReturnMsg.consSuccess( list);
    }
    /**
     * @Description:  地图井盖
     * @Date:  2021/11/18 20:16
     * @Param: []
     * @return: com.bcbim.common.response.vo.ReturnPageMsg
     * @Author: lihonggang
     **/
    @RequestMapping("/listAssetInformation")
    @Translate
    public ReturnMsg listAssetInformation(){

        HashMap<Object, Object> map = new HashMap<>();

        List<ListAssetInformationVO> listAsset = wisdomBigScreenServiceImpl.listAssetInformation();
        List<ListAssetInformationVO> listAssetAlarm = wisdomBigScreenServiceImpl.listAssetAlarmInformation();
        ArrayList<ListAssetInformationVO> listAssetNomal = new ArrayList<>();
        listAssetNomal.addAll(listAsset);
        listAssetNomal.addAll(listAssetAlarm);
        listAsset.retainAll(listAssetAlarm);
        listAssetNomal.removeAll(listAsset);
        map.put("listAssetAlarm",listAssetAlarm);
        map.put("listAssetNomal",listAssetNomal);

        return ReturnMsg.consSuccess(map);
    }
    /**
     * @Description:  最后一个巡检员的巡检路线
     * @Date:  2021/11/19 15:02
     * @Param: []
     * @return: com.bcbim.common.response.vo.ReturnMsg
     * @Author: lihonggang
     **/
    @RequestMapping("/listInspectionPosition")
    public ReturnMsg listInspectionPosition(){

        List<InspectionPositionVO> list = wisdomBigScreenServiceImpl.listInspectionPosition();
        list.stream().forEach(inspectionPositionVO -> {
            double[] LngLon = LngLonUtil.gcj02_To_Gps84(Double.valueOf(inspectionPositionVO.getLatitude()), Double.valueOf(inspectionPositionVO.getLongitude()));
            inspectionPositionVO.setLatitude(Double.toString(LngLon[0]));
            inspectionPositionVO.setLongitude(Double.toString(LngLon[1]));
        });
        return ReturnMsg.consSuccess(list);
    }

    @RequestMapping("/listProblemInformation")
    public ReturnMsg listProblemInformation(){

        List<ListProblemInformationVO> list = wisdomBigScreenServiceImpl.listProblemInformation();
        TranslateHandle.translationData(list);
        return ReturnMsg.consSuccess(list);
    }
}
